<?php

class RequestHandler
{
	var $ready = false;

	final public function __construct ($config=array(), $init=true)
	{
		foreach ($config as $k=>$v) $this->$k = $v;
		$this->config = $config;
		if ($init) $this->init();
	} // end of __construct
	final public function init ($force=false)
	{
		if ($this->ready && !$force) return true; $this->ready = false;
		return $this->ready = $this->_init();
	} // end of method init
	public function dispatch ()
	{
		$f = isset($_GET['act']) ? $_GET['act'] : 'handle';
		$h = $f.'_'.$_SERVER['REQUEST_METHOD'];

		if     (method_exists($this, $h)) return array($this, $h);
		if     (method_exists($this, $f)) return array($this, $f);
# FIXME :
# unknown action
		return array($this, 'handle');
	} // end of method handle

	public function handle ()
	{
	} // end of method handle
	public function _init()
	{
		return true;
	} // end of method custom_init
}

